﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EmotionRecognitionEntities;
using EmotionRecognitionMessages;
namespace EmotionRecognitionGui
{//
    public partial class ImageAnalysis : BasicForm
    {
        GuiManager guiManager;//

        public ImageAnalysis()
        {
            try
            {
                guiManager = GuiManager.Instance;
                InitializeComponent();

            }
            catch (Exception e)
            {
                MessageBox.Show("Error: " + e.ToString());
            }
        }
        public void ReEnter()
        {

        }
        public void DisposeObjectsInherent()
        {
            buttonExternal2.Dispose();
            label4.Dispose();
            buttonDataBase2.Dispose();
            label2.Dispose();
            buttonTakeImage2.Dispose();
            label1.Dispose();
        }
        public void DisposeObjectsInstance()
        {
            buttonExternalImages.Dispose();
            buttonDataBaseImages.Dispose();
            buttonTakeImage.Dispose();
            labelTakeImage.Dispose();
            labelDataBaseImages.Dispose();
            labelExternalImages.Dispose();
            label3.Dispose();
        }
        

        protected void buttonExternalImagesEvent()
        {
            OpenFileDialog openImage = null;
            try
            {
                openImage = new OpenFileDialog();
                openImage.Title = "Open image";
                openImage.Filter = "JPEG Image|*.jpg|GIF Image|*.gif";
                if (openImage.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {

                    Messages msgs = new Messages();
                    ReplyMsg imageNameMsg = msgs.getExternalImageName();
                    ReplyMsg copyFileMsg;
                    System.IO.FileInfo fInfo = new System.IO.FileInfo(openImage.FileName);
                    if (imageNameMsg.MessageState == true)
                    {
                        copyFileMsg = msgs.copyFile(openImage.FileName, Environment.GetEnvironmentVariable("ExternalPictures"), (string)imageNameMsg.ParamArray[0] + fInfo.Extension);
                        if (copyFileMsg.MessageState == true)
                            msgs.CreateNewPicutreInDB((string)imageNameMsg.ParamArray[0] + fInfo.Extension, (int)GuiManager.Folders.Externals);
                    }

                }
            }
            finally
            {
                if (openImage != null)
                {
                    openImage.Dispose();
                }
            }

        }

        protected void buttonBack_Click(object sender, EventArgs e)
        {
            guiManager.SwitchForms(this, guiManager.mainMenuReviewerGui);
        }

        protected void buttonTakeImage2_Click(object sender, EventArgs e)
        {
            guiManager.takeImageGui.EnterTakeImage();
            guiManager.SwitchForms(this, guiManager.takeImageGui);
        }

        protected void buttonDataBase2_Click(object sender, EventArgs e)
        {
            guiManager.dataBaseImagesGui.ShowFirstImage() ;
            guiManager.SwitchForms(this, guiManager.dataBaseImagesGui);
        }

        protected void buttonExternal2_Click(object sender, EventArgs e)
        {
            guiManager.dataBaseImagesGui.ShowFirstImage();
            buttonExternalImagesEvent();
        }

        protected void buttonTakeImage_Click(object sender, EventArgs e)
        {
            guiManager.takeImageGui.EnterTakeImage();

            guiManager.SwitchForms(this, guiManager.takeImageGui);
        }

        protected void buttonDataBaseImages_Click(object sender, EventArgs e)
        {

            guiManager.dataBaseImagesGui.ReEnter();
            guiManager.SwitchForms(this, guiManager.dataBaseImagesGui);
        }
        protected void buttonExternalImages_Click(object sender, EventArgs e)
        {
            buttonExternalImagesEvent();
        }

    }
}
